module(..., package.seeall)

require "utils"

local function base64Test()
    local originStr = "HelloWorld"
    local encodeStr = crypto.base64_encode(originStr, string.len(originStr))
    log.info("testCrypto.base64_encode", encodeStr)
    log.info("testCrypto.base64_decode", crypto.base64_decode(encodeStr, string.len(encodeStr)))
end

local function md5Test()
    local originStr = "HelloWorld"
    log.info("testCrypto.md5", crypto.md5(originStr, string.len(originStr)))
end

local function aesTest()
    local originStr = "123"
    local key = "00000005000000000004"
    -- 加密模式  AES128 ECB nopadding  key "00000005000000000002"
    local encodeStr = crypto.aes_encrypt("ECB","ZERO",originStr,"1234567890123456")
    log.info(originStr, "encrypt", string.toHex(encodeStr))
end

local function aes_cbc_256_padding5()
    local originStr = "HelloWorld"
    local key = "12345678901234567890123456789012"
    local iv = "1234567890666666"
    local encodeStr = crypto.aes_encrypt("CBC","PKCS5",originStr,key,iv)

    log.info(originStr,"encrypt AES CBC 256",crypto.base64_encode(encodeStr,string.len(encodeStr)))
end
local function cryptoTest()
    base64Test()
    md5Test()
    aes_cbc_256_padding5()
end


sys.timerLoopStart(cryptoTest, 5000)


